package org.ruanjj.multithread;

public class Clerk{
    public int goods; //商品库存


    public synchronized void add(){
        if(goods > 20){
            try {
                wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        notify();
        goods++;
    }

    public synchronized void delete(){
        if(goods < 0){
            try {
                wait();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        notify();
        goods--;
    }
}
